<template>
  <div>
      <h1>购物车列表</h1>
      <p v-for="i in cartlist" :key="i.id">
          {{i.name}}--{{i.price}}元--{{i.num}}个--{{i.price*i.num}}元
      </p>
      <p>总额：{{total_money}}</p>
      <div v-for="i in couponlist" :key="i.id">
          <input type="radio" v-model="coupon" :value="i.money">{{i.title}}
       </div>
      <p>
          实际支付{{total_money-coupon}}元
      </p>
  </div>
</template>


<script>
import axios from 'axios'
export default {
    data(){
        return{
            cartlist:[],
            couponlist:[],
            coupon:""
        }
    },
    created(){
        var uid=sessionStorage.getItem("uid")
        axios({
            url:"http://127.0.0.1:8000/conpon?uid="+uid,
            method:"get",
        }).then(resp=>{
            console.log(resp.data)
            this.couponlist=resp.data
            var carts=sessionStorage.getItem(uid)
            this.cartlist=JSON.parse(carts)
        }).catch(error=>{
            console.log(error.respone)
        })
        
        
    },
    computed:{
       total_money(){
           var total=0
           for(var i=0;i<this.cartlist.length;i++){
               total+=this.cartlist[i].num*this.cartlist[i].price
           }
           return total
       }
    }
}
</script>


<style>


</style>